package com.tangtanwei.hotel.controller;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tangtanwei.hotel.entity.RoomNumber;
import com.tangtanwei.hotel.service.RoomNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


@RequestMapping("/roomNumber")
@RestController
public class RoomNumberController {
    @Autowired
    private RoomNumberService roomNumberService;


    // 导入房间名单
//    @RequestMapping("/import")
//    public void importRoomNumber(@RequestParam("file") MultipartFile multipartFile){
//        try {
//            InputStream inputStream = multipartFile.getInputStream();
//            ExcelReader excelReader = ExcelUtil.getReader(inputStream);
//            List<List<Object>> read = excelReader.read(1, excelReader.getRowCount());
//
//            for (List<Object> list : read) {
//                String number = list.get(0).toString();
//                    String number = list.get(1).toString();
//
//            }
//
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//
//    }

    // 分配房给用户   roomId-房间号  userId-用户id
    @RequestMapping("/add")
    public String post(String roomId,String userId){
        return roomNumberService.post(roomId,userId);
    }

    // 退房
    @RequestMapping("/del")
    public String del(String roomId,String userId){
        return roomNumberService.del(roomId,userId);
    }

    // 查找某一房间类型id下所有房间号
    @RequestMapping
    List<RoomNumber> getAll(String parentId){
        return roomNumberService.list(new QueryWrapper<RoomNumber>().lambda().eq(RoomNumber::getParentId,parentId));
    }







}
